package com.healthtop.web;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.healthtop.common.Page;
import com.healthtop.common.Specification;
import com.healthtop.common.Views;
import com.healthtop.dto.XsGameDetailsDto;
import com.healthtop.dto.XsGameGategoryDto;
import com.healthtop.service.DIYService;
import com.healthtop.service.XsArticleCategoryService;
import com.healthtop.service.XsGameDetailsService;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Controller
@RequestMapping("/xsGameDetails")
public class XsGameDetailsController {

    @Autowired
    private XsGameDetailsService xsGameDetailsService;

    @Autowired
    private DIYService diyService;

    /**
     * 获取列表
     *
     * @param page
     * @return
     */
    @RequestMapping("/list")
    public String list(Page page) {
        diyService.selectXsGameDetailsPage(page);
        return Views.XS_GAME_DETAILS_LIST;
    }


    /**
     * 进入新增/编辑页面
     *
     * @param xsGameDetailsDto
     * @return
     */
    @RequestMapping("/forward")
    public String forward(XsGameDetailsDto xsGameDetailsDto) {
        xsGameDetailsService.forward(xsGameDetailsDto);
        return Views.XS_GAME_DETAILS_FORM;
    }

    /**
     * 进行新增/编辑操作
     *
     * @param xsGameDetailsDto
     * @return
     */
    @RequestMapping("/operate")
    public String operate(XsGameDetailsDto xsGameDetailsDto) {
        xsGameDetailsService.operate(xsGameDetailsDto);
        return Views.REDIRECT_XS_GAME_DETAILS_List;
    }

    /**
     * 进行删除操作
     *
     * @param xsGameDetailsDto
     * @return
     */
    @RequestMapping("/delete")
    public String delete(XsGameDetailsDto xsGameDetailsDto) {
        xsGameDetailsService.delete(xsGameDetailsDto);
        return Views.REDIRECT_XS_GAME_DETAILS_List;
    }

    /**
     * 上传文本的图片
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/upload")
    @ResponseBody
    public String fileUpload(HttpServletRequest request, HttpServletResponse response) {
        return diyService.upload(request, response);
    }

    @RequestMapping("/videoUpload")
    @ResponseBody
    public String videoUpload(HttpServletRequest request, HttpServletResponse response) {
        return diyService.videoUpload(request, response);
    }

}
